package cn.gzsxt.music.controller;

import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import cn.gzsxt.music.query.LableQueryObject;
import cn.gzsxt.music.query.SongListQueryObject;
import cn.gzsxt.music.query.SongQueryObject;
import cn.gzsxt.music.query.UserQueryObject;
import cn.gzsxt.music.service.PowerService;
import cn.gzsxt.music.service.RoleService;
import cn.gzsxt.music.service.SongListService;
import cn.gzsxt.music.vo.MsgObj;

@Controller
@Scope("request")
@RequestMapping("/songList")
public class SongListController {

	@Autowired
	private SongListService songListService;

	@RequestMapping("songListPage")
	public String rolePage() {
		return "songListPage";
	}

	@RequestMapping("songListList")
	@ResponseBody
	public Map<String, Object> roleList(SongListQueryObject qo) {
		Map<String, Object> result = songListService.selectSongListData(qo);
		return result;
	}

	@RequestMapping("getAllUser")
	@ResponseBody
	public Map<String, Object> getAllUser(UserQueryObject qo) {
		Map<String, Object> result = songListService.getAllUser(qo);
		return result;
	}

	@RequestMapping("getAllSong")
	@ResponseBody
	public Map<String, Object> getAllSong(LableQueryObject qo) {
		Map<String, Object> result = songListService.getAllSong(qo);
		return result;
	}

	@RequestMapping("getAllLabel")
	@ResponseBody
	public Map<String, Object> getAllLabel(LableQueryObject qo) {
		Map<String, Object> result = songListService.getAllLabel(qo);
		return result;
	}

	@RequestMapping("addSongList")
	@ResponseBody
	public MsgObj addSongList(@RequestParam Map<String, Object> params) {

		int row = songListService.saveSongList(params);

		Map<String, Object> ssList = new HashMap<>();
		ssList.put("ssList_date", new Date());

		MsgObj msgObj = new MsgObj(0, "添加歌单失败");
		if (row == 1) {
			msgObj = new MsgObj(1, "添加歌单成功");
		}
		return msgObj;
	}

	@RequestMapping("updateSongList")
	@ResponseBody
	public MsgObj updateSongList(@RequestParam Map<String, Object> params) {

		int row = songListService.updateSongList(params);

		MsgObj msgObj = new MsgObj(0, "修改歌单失败");
		if (row == 1) {
			msgObj = new MsgObj(1, "修改歌单成功");
		}

		return msgObj;
	}

	@RequestMapping("deleteSongListById")
	@ResponseBody
	public MsgObj deleteSongListById(Long songList_id) {

		int row = songListService.deleteSongListById(songList_id);

		MsgObj msgObj = new MsgObj(0, "删除歌单失败");
		if (row == 1) {
			msgObj = new MsgObj(1, "删除歌单成功");
		}
		return msgObj;
	}

	@RequestMapping("myLabel")
	@ResponseBody
	public Map<String, Object> myLabel(String songList_id) {
		Map<String, Object> result = songListService.getLabelBysongList_id(songList_id);
		return result;
	}

	@RequestMapping("myUser")
	@ResponseBody
	public Map<String, Object> myUser(String songList_id) {
		Map<String, Object> result = songListService.getUserBysongList_id(songList_id);
		return result;
	}

	@RequestMapping("mySong")
	@ResponseBody
	public Map<String, Object> mySong(String songList_id) {
		Map<String, Object> result = songListService.getSongBysongList_id(songList_id);
		return result;
	}

}
